package com.lwc.cfdns.controller.admin.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lwc.cfdns.constants.ConstantsUrl;
import com.lwc.cfdns.pojo.bo.system.GroupDataBO;
import com.lwc.cfdns.pojo.dto.ValidGroup;
import com.lwc.cfdns.pojo.dto.system.GroupDataDTO;
import com.lwc.cfdns.pojo.entity.SystemGroupData;
import com.lwc.cfdns.pojo.vo.system.GroupDataVO;
import com.lwc.cfdns.service.impl.SystemGroupDataServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * 组合数据管理
 *
 * @author luwc
 * @title GroupDataController
 * @description
 * @time 2023/7/12 16:52:44
 * @version: 1.0
 */
@RestController
@RequestMapping(ConstantsUrl.ADMIN + "/system/group")
public class GroupDataController {
    @Autowired
    private SystemGroupDataServiceImpl systemGroupDataService;

    /**
     * 创建
     *
     * @param groupDataDTO
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/12 17:00:53
     */
    @PreAuthorize("hasAnyAuthority('system:group:data:create')")
    @PostMapping("/data")
    public Map<String, Object> create(@Validated(ValidGroup.Create.class) @RequestBody GroupDataDTO groupDataDTO) {
        return systemGroupDataService.create(groupDataDTO);
    }

    /**
     * 修改
     *
     * @param groupDataDTO
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/12 17:03:18
     */
    @PreAuthorize("hasAnyAuthority('system:group:data:update')")
    @PutMapping("/data")
    public Map<String, Object> update(@Validated(ValidGroup.Update.class) @RequestBody GroupDataDTO groupDataDTO) {
        return systemGroupDataService.update(groupDataDTO);
    }

    /**
     * 详情
     *
     * @param id
     * @return GroupDataVO
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/12 17:06:03
     */
    @PreAuthorize("hasAnyAuthority('system:group:data:view')")
    @GetMapping("/data/{id}")
    public GroupDataVO view(@PathVariable("id") @NotNull(message = "ID不能为空") Long id) {
        return systemGroupDataService.view(id);
    }

    /**
     * 删除
     *
     * @param ids
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/12 17:07:52
     */
    @PreAuthorize("hasAnyAuthority('system:group:data:delete')")
    @DeleteMapping("/data/{ids}")
    public Map<String, Object> delete(@PathVariable("ids") @NotBlank(message = "ids不能为空") String ids) {
        return systemGroupDataService.delete(ids);
    }

    /**
     * 列表
     *
     * @param groupDataBO
     * @return IPage<SystemGroupData>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/7/12 17:08:58
     */
    @PreAuthorize("hasAnyAuthority('system:group:data:lists')")
    @GetMapping("/data")
    public IPage<SystemGroupData> lists(GroupDataBO groupDataBO) {
        return systemGroupDataService.lists(groupDataBO);
    }
}
